package com.myapp.api.service.impl;

import com.myapp.api.entity.Student;
import com.myapp.api.mapper.StudentMapper;
import com.myapp.api.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper mapper;

    @Override
    public List<Student> getStudents() {
        return mapper.getStudents();
    }

    @Override
    public Student getStudentById(@Param("id") Integer id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public Student getStudentBySid(@Param("sid") String sid) {
        return mapper.getStudentBySid(sid);
    }

    @Override
    public Integer getStudentByOneSid(@Param("sid") String sid) {
        return mapper.getAdminByOneSid(sid);
    }

    @Override
    public List<Student> getStudentBySname(@Param("sname") String sname) {
        return mapper.getStudentBySname(sname);
    }

    @Override
    public int addStudent(@Param("record") Student record) {
        return mapper.insertSelective(record);
    }

    @Override
    public int deleteStudentById(@Param("id") Integer id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int putStudent(@Param("record") Student record) {
        return mapper.updateByPrimaryKeySelective(record);
    }
}
